<?php
// File Security Check
if ( ! empty( $_SERVER['SCRIPT_FILENAME'] ) && basename( __FILE__ ) == basename( $_SERVER['SCRIPT_FILENAME'] ) ) :
	die ( 'You do not have sufficient permissions to access this page!' );
endif;

/* Template Name: Home */

get_header(); ?>

<?php global $nice_options; ?>

	<?php

			$social_items = array();
			$nice_social_enable = get_option( 'nice_social_enable' );

			if ( nice_bool( $nice_social_enable ) ) :
				$social_items = nice_social_icons();
			endif;

			$nice_phone_number = $nice_options['nice_phone_number'];

			$home_social_class = ( empty( $social_items ) || $nice_phone_number == '' ) ? 'home-social-full-width' : '';

			if ( ! empty( $social_items ) || $nice_phone_number != '' ) : ?>
					<!-- BEGIN .home-social -->
					<section class="home-social home-block <?php echo $home_social_class; ?> clearfix">

						<div class="col-full">

								<?php if ( ! empty( $social_items ) ) : ?>
										<div class="social-links clearfix">

											<ul class="social">
												<?php echo $social_items; ?>
											</ul>

										</div>

								<?php endif; ?>
								<?php if ( $nice_phone_number != '' ) : ?>

										<div class="main-title">
											<div class="right">
												<span class="call-now"><?php echo $nice_options['nice_call_now_text']; ?></span>
												<span class="call-number"><?php echo $nice_options['nice_phone_number']; ?></span>
											</div>
										</div>

								<?php endif; ?>

						</div>

					<!-- END .home-social -->
					</section>
			<?php endif; ?>
	<?php

		$nice_welcome_message = get_option( 'nice_welcome_message' );
		$nice_welcome_message_extended = get_option( 'nice_welcome_message_extended' );

		if ( ( $nice_welcome_message != '' ) || ( $nice_welcome_message_extended != '' ) ) : ?>

				<!-- BEGIN .welcome-message -->
				<section class="welcome-message home-block clearfix">

						<div class="col-full">

								<?php if ( $nice_welcome_message != '' ) : ?>
										<header>
											<h2><?php echo stripslashes( htmlspecialchars_decode( nl2br( $nice_welcome_message ) ) ); ?></h2>
										</header>
								<?php endif ;?>

								<?php if ( $nice_welcome_message_extended != '' ) : ?>
										<p><?php echo stripslashes( htmlspecialchars_decode( nl2br( $nice_welcome_message_extended ) ) ); ?></p>
								<?php endif ;?>

						</div>

				<!-- END .welcome-message -->
				</section>

	<?php endif; ?>

                                
        <?php $terms = get_terms("service-category");
              if ( !empty( $terms ) && !is_wp_error( $terms ) ): ?>
                                
        <section id="home-service-category" class="home-block home-service-category clearfix">

            <div class="col-full">

                <!-- BEGIN .home-block-header -->
                <div class="home-block-header">
                    <header>
                        <h3>Nuestras unidades</h3>
                    </header>
                <!-- END .home-block-header -->
                </div>

                <ul id="service-category" class="four-col-grid service-grid-four-col grid clearfix">

                    <?php $tcount = 0;
                          foreach ( $terms as $term ) {
                            $tcount++;
                            $tid = $term->term_id;
                            $tname = $term->name;
                            //$timg = ff_get_field_from_section('service_category', 'service_category_image', 'options', 'taxonomy', $tid);
                            $timg = get_terms_meta($tid, 'service-category-image');
                            //$tdesc = ff_get_field_from_section('service_category', 'service_category_short_description', 'options', 'taxonomy', $tid);
                            $tdesc = get_terms_meta($tid, 'service-category-short-description');
                            $tclass = ($tcount == 4) ? "last" :"";
                    ?>
                            <li class="<?php echo $tclass ?>">

                                <div class="service-category-image">
                                    <?php if( $timg == ""){ ?>
                                        <img src="default_service.png" alt="<?php echo $tname ?>" />
                                    <?php } else { ?>
                                        <img src="<?php print($timg[0]); ?>" alt="<?php echo $tname ?>" />
                                    <?php } ?>
                                    
                                </div>

                                <div class="service-category-content">
                                    <div class="service-category-title"><?php echo $tname ?></div>
                                    <div class="service-category-short-description"><?php echo $tdesc[0] ?></div>
                                </div>
                            </li>

                    <?php } ?>

                </ul>

            <!-- END .col-full -->
            </div>

            <div class="home-services-button"><a href="<?php bloginfo( 'url' ); ?>/tratamientos" class="button-bg" title="">Vea nuestros tratamientos</a></div>

        <!-- END #home-service .home-block -->
        </section>                       
        <?php endif; ?>                     
                                
        <?php

				$nice_service_enable = get_option( 'nice_service_enable' );
				$nice_service_title = get_option( 'nice_service_title' );
				$nice_service_order = get_option( 'nice_service_order' );

				if ( $nice_service_enable == 'true' ) :

				?>
				<!-- BEGIN #home-service .home-block -->
				<section id="home-service" class="home-block home-service clearfix">

						<div class="col-full">

						<!-- BEGIN .home-block-header -->
						<div class="home-block-header">

								<?php if ( $nice_service_title != '' ) : ?>
										<header>
											<h3><?php echo stripslashes( $nice_service_title ); ?></h3>
										</header>
								<?php endif; ?>

						<!-- END .home-block-header -->
						</div>

						<?php

						$query = new WP_Query( array(
											'post_type'			=> 'service',
											'orderby'			=> $nice_service_order,
											'posts_per_page'	=> 4,
											'order'				=> 'ASC'
									)
								);
						?>

						<ul id="service" class="four-col-grid service-grid-four-col grid clearfix">

						<?php

						$loop = 0;

						$columns = 4;

						if ( $query->have_posts() ) :
							while ( $query->have_posts() ) :
								$query->the_post();

								$loop++; ?>

								<li data-id="id-<?php echo $loop; ?>" id="post-<?php the_ID(); ?>" class="<?php if ( $loop % $columns == 0 ) echo 'last'; if ( ( $loop - 1 ) % $columns == 0 ) echo 'first'; ?>">

									<?php if ( has_post_thumbnail() ) : ?>
										<div class="view view-more">
											<a href="<?php the_permalink(); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>">
												<?php nice_image( array( 'key' => 'service-image', 'width' => 480, 'height' => 390 ) ) . "\n"; ?>
												<div class="mask"></div>
											</a>
										</div>
									<?php endif; ?>

									<div class="content">
										<span class="service-title">
											<a href="<?php the_permalink(); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>">
												<?php the_title(); ?>
											</a>
										</span>
										<?php nice_excerpt(60); ?>
										
									</div>
								</li>

						<?php endwhile; endif; ?>

						</ul>

						<!-- END .col-full -->
						</div>
                                    
                                                <div class="home-services-button"><a href="#" class="button-bg" title="">Vea nuestros tratamientos</a></div>

				<!-- END #home-service .home-block -->
				</section>

        <?php endif; ?>                        
                                
                                
	<?php

				$nice_staff_enable = get_option( 'nice_staff_enable' );
				$nice_staff_title = get_option( 'nice_staff_title' );
				$nice_staff_order = get_option( 'nice_staff_order' );

				if ( $nice_staff_enable == 'true' ) :

				?>
				<!-- BEGIN #home-staff .home-block -->
				<section id="home-staff" class="home-block home-staff clearfix">

					<div class="col-full">

						<!-- BEGIN .home-block-header -->
						<div class="home-block-header col-full">

								<?php if ( $nice_staff_title != '' ) : ?>
										<header>
											<h3><?php echo stripslashes( $nice_staff_title ); ?></h3>
										</header>
								<?php endif; ?>

						<!-- END .home-block-header -->
						</div>

						<?php


						$query = new WP_Query( array(
												'post_type'			=> 'staff',
												'orderby'			=> $nice_staff_order,
												'posts_per_page'	=> 4,
												'order'				=> 'ASC'
											)
									);

						?>

						<ul id="staff" class="three-col-grid staff-grid-three-col grid clearfix">

						<?php

						$loop = 0;

						$columns = 3;

						if ( $query->have_posts() ) :
							while ( $query->have_posts() ) :
								$query->the_post();

								$loop++; ?>

								<li data-id="id-<?php echo $loop; ?>" id="post-<?php the_ID(); ?>" class="<?php if ( $loop % $columns == 0 ) echo 'last'; if ( ( $loop-1 ) % $columns == 0 ) echo 'first'; ?>">

									<?php
										$image_class = $image = '';
										if ( has_post_thumbnail() ) :
											$image = nice_image( array( 'echo' => 'false', 'id' => get_the_ID(), 'key' => 'staff-image', 'width' => 480, 'height' => 480 ) );
											$image_class = 'has-image';
										endif;
									?>

									<div class="<?php echo $image_class; ?>">

									<?php if ( has_post_thumbnail() ) : ?>
										<a href="<?php the_permalink(); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>">
											<?php echo $image; ?>
										</a>
									<?php endif; ?>

										<div class="content">
												<span class="staff-title">
													<a href="<?php the_permalink(); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>">
															<?php the_title(); ?>
													</a>
												</span>

												<div class="staff-deparment">
													<?php echo get_the_term_list( get_the_ID(), 'department', '', ', ', '' ); ?>
												</div>

												<div class="staff-excerpt">
													<?php nice_excerpt( 120 ); ?>
												</div>
										</div>

									</div>

								</li>

						<?php endwhile; endif; ?>

						</ul>

						<!-- END .col-full -->
						</div>

						<?php $nice_staff_button_text = get_option( 'nice_staff_button_text' );
							  $nice_staff_button_url = get_option( 'nice_staff_button_url' );

							if ( $nice_staff_button_text != '' && $nice_staff_button_url != '' ) : ?>
								<div class="meet-doctor-button"><a href="<?php echo $nice_staff_button_url; ?>" class="button-bg" title="<?php echo $nice_staff_button_text; ?>"><?php echo $nice_staff_button_text; ?></a></div>
						<?php endif; ?>

				<!-- END #home-staff .home-block -->
				</section>

	<?php endif; ?>



	<?php

				$nice_testimonial_enable = get_option( 'nice_testimonial_enable' );
				$nice_testimonial_title = get_option( 'nice_testimonial_title' );
				$nice_testimonial_order = get_option( 'nice_testimonial_order' );

				if ( $nice_testimonial_enable == 'true' ) :

					$query = new WP_Query( array(
												'post_type'			=> 'feedback',
												'orderby'			=> $nice_testimonial_order,
												'posts_per_page'	=> 3,
												'order'				=> 'ASC'
												)
								);

					if ( $query->have_posts() ) : ?>

					<!-- BEGIN #container -->
					<div id="container" class="clearfix">

					<!-- BEGIN #content -->
					<section id="content" class="home-testimonial home-block clearfix">


						<div class="col-full">

						<!-- BEGIN .home-block-header -->
						<div class="home-block-header">

								<?php if ( $nice_testimonial_title != '' ) : ?>
										<header>
											<h3><?php echo stripslashes( $nice_testimonial_title ); ?></h3>
										</header>
								<?php endif; ?>

						<!-- END .home-block-header -->
						</div>

						<?php

						 while ( $query->have_posts() ) : $query->the_post(); ?>

						 <article>

							<div class="clearfix">

										<?php
												$image_class = $image = '';
												if ( has_post_thumbnail() ) :
													$image = nice_image( array( 'echo' => 'false', 'id' => get_the_ID(), 'key' => 'feedback-image', 'width' => 200, 'height' => 200 ) );
													$image_class = 'has-image';
												endif;
										?>
											<div class="<?php echo $image_class; ?>">

												<?php echo $image; ?>

												<div class="content testimonial">
												   <div class="feedback-text"><?php the_content(); ?></div>
												   <?php
														$meta = get_post_custom( get_the_ID() );
														$feedback_author = '';

														if ( ( isset( $meta['feedback_author'] ) && ( $meta['feedback_author'][0] != '' ) ) || ( isset( $meta['feedback_url'] ) && ( $meta['feedback_url'][0] != '' ) ) ):
															$feedback_author = '<span class="feedback-author clearfix">';

															if ( isset( $meta['feedback_author'] ) && ( $meta['feedback_author'][0] != '' ) ):
																$feedback_author .= '<cite class="feedback-author">' . $meta['feedback_author'][0] . '</cite>';
															endif;

															if ( isset( $meta['feedback_url'] ) && ( $meta['feedback_url'][0] != '' ) ) :
																	$feedback_author .= ' &mdash; <a href="' . $meta['feedback_url'][0] . '" title="' . esc_attr( $meta['feedback_author'][0] ) . '" class="feedback-url">' . $meta['feedback_url'][0] . '</a>';
															endif;

															$feedback_author .= '</span>';

														endif;

														echo $feedback_author;
												   ?>
												</div>
										</div>
								</div>

			</article>

						<?php endwhile; ?>

						<?php
							$nice_testimonial_button_text = get_option( 'nice_testimonial_button_text' );
							$nice_testimonial_button_url = get_option( 'nice_testimonial_button_url' );

							if ( $nice_testimonial_button_text != '' && $nice_testimonial_button_url != '' ) : ?>
								<div class="readmore-feedback"><a href="<?php echo $nice_testimonial_button_url; ?>"  title="<?php echo $nice_testimonial_button_text; ?>"><?php echo $nice_testimonial_button_text; ?></a></div>
							<?php endif; ?>

						<!-- END .col-full -->
						</div>

						<!-- END #content -->
						</section>

						<!-- BEGIN #sidebar -->
						<aside  class="home-sidebar" id="sidebar" role="complementary">
							<?php dynamic_sidebar( 'home' ); ?>
						<!-- END #sidebar -->
						</aside>

						<!-- END #container -->
						</div>
				<?php endif; ?>

				<?php endif; ?>

<?php get_footer(); ?>